<%--
  @author supun nimesh karunathilaka
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">
    $(document).ready(function () {
        var pls_enter_applicant_name = "<br>" + document.getElementById("pls_enter_applicant_name").value;
        var pls_enter_submit_date = "<br>" + document.getElementById("pls_enter_submit_date").value;
        var pls_enter_applicant_address = "<br>" + document.getElementById("pls_enter_applicant_address").value;
        var pls_enter_valid_email = "<br>" + document.getElementById("pls_enter_valid_email").value;
        var pls_enter_valid_phone_No = "<br>" + document.getElementById("pls_enter_valid_phone_No").value;
        var pls_enter_valid_NIC_No = "<br>" + document.getElementById("pls_enter_valid_NIC_No").value;
        var pls_select_nationality = document.getElementById("pls_select_nationality").value;
        var pls_select_gn_division = $("#pls_select_gnDivision").val();
        var pls_select_applicant_type = $("#pls_select_applicant_type").val();
        var pls_enter_annual_income = $("#pls_enter_annual_income").val();
        var pls_enter_valid_annual_income = $("#pls_enter_valid_annual_income").val();
        var applicant_age_validate = $("#applicant_age_validate").val();
        var pls_enter_the_applicant_dob = $("#pls_enter_the_applicant_dob").val();

        $("#gov-land-init-OutrightGrant-application-form").validate({
            rules: {
                personId: {
                    required: true
                },
                submitDate: {
                    required: true,
                    isDateFormated: true
                },
                personAddress: {
                    required: true
                },
                emailId: {
                    email: true
                },
                mobileId: {
                    phoneNo: true
                },
                landPhoneId: {
                    phoneNo: true
                },
                personNICNoId: {
                    NICNo: true
                },
                nationalityIdtrue: {
                    nationality: true
                },
                nationalityIdfalse: {
                    nationality: true
                },
                dateOfBirth: {
                    required: true,
                    isDateFormated: true
                },
                annualIncome: {
                    required: true,
                    number: true
                },
                gnDivisionId: {
                    selectBox: "default"
                },
                applicantType0: {
                    required: true
                },
                applicantType1: {
                    required: true
                }
            },
            messages: {
                personId: {
                    required: pls_enter_applicant_name
                },
                submitDate: {
                    required: pls_enter_submit_date
                },
                personAddress: {
                    required: pls_enter_applicant_address
                },
                mailId: pls_enter_valid_email,
                mobileId: pls_enter_valid_phone_No,
                landPhoneId: pls_enter_valid_phone_No,
                personNICNoId: pls_enter_valid_NIC_No,
                nationalityIdtrue: {
                    nationality: pls_select_nationality
                },
                nationalityIdfalse: {
                    nationality: pls_select_nationality
                },
                gnDivisionId: {
                    selectBox: pls_select_gn_division
                },
                applicantType0: {
                    required: pls_select_applicant_type
                },
                applicantType1: {
                    required: pls_select_applicant_type
                },
                annualIncome: {
                    required: pls_enter_annual_income,
                    number: pls_enter_valid_annual_income
                },
                dateOfBirth: {
                    required: pls_enter_the_applicant_dob,
                    ageValidate: applicant_age_validate
                }
            }
        });
    });

    $(function () {

        var mode = document.getElementById("edit_mode").value;
        if (mode == 2 || mode == 3 || mode == 4 || mode == 5 || mode == 6 || mode == 8 || mode == 9) {
            var fieldIds = new Array(
                    'submitDate',
                    'ltlYes',
                    'ltlNo',
                    'planNumber',
                    'lotNumber',
                    // 'agreementNo',
                    'district',
                    'dsDivision',
                    'hectareId',
                    'acreId',
                    'roodsId',
                    'perchesId',
                    'purposeId',
                    'select_all_col_managers',
                    'removeDsButton'
                    , 'gnDivisionId',
                    'districtId',
                    'dsDivisionId',
                    'addChild'
            );
            enableFields(fieldIds);
        }
    });
</script>
<script type="text/javascript" language="javascript">
    function showLandDetails() {
        $('#land-details').show();
        $('#agreement-no').hide();
        $('#legend-land').show();
        $('#legend-agreement').hide();

    }

    function hideLandDetails() {
        $('#land-details').hide();
        $('#agreement-no').show();
        $('#legend-land').hide();
        $('#legend-agreement').show();

    }

    $(function () {
        var personaDetail = $('#personDetails').html();
        var instituteDetail = $('#instituteDetails').html();
        var division = $('#division').html();

        $('#personDetails').html('');
        $('#instituteDetails').html('');
        $('#division').html('');

        $('#applicantType0').bind('click', function () {
            $('#instituteDetails').html(instituteDetail);
            $('#personDetails').html('');
            $('#division').html(division);
        });
        $('#applicantType1').bind('click', function () {
            $('#personDetails').html(personaDetail);
            $('#instituteDetails').html('');
            $('#division').html(division);
        });
        if ($('#applicantType0').is(':checked')) {
            $('#personDetails').html('');
            $('#instituteDetails').html(instituteDetail);
            $('#division').html(division);
        } else if ($('#applicantType1').is(':checked')) {
            $('#personDetails').html(personaDetail);
            $('#instituteDetails').html('');
            $('#division').html(division);
        }

        if ($('#edit_mode').val() != 0 && $('#edit_mode').val() != 1) {
            enableFields(new Array('applicantType0', 'applicantType1'));
        }
    });

    function getDsDivisionByDistrict() {
        var oSelect = document.getElementById('districtId');
        //var options1 = '<option value="0"> -- Select -- </option> ';
        var options1 = '<option value="0">' + $('#select').val() + '</option> ';
        for (var iCount = 0; oSelect.options[iCount]; iCount++) {
            if (oSelect.options[iCount].selected == true) {
                var id = oSelect.options[iCount].value;
                $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 2},
                        function (data) {
                            var ds = data.dsDivisionList;
                            for (var i = 0; i < ds.length; i++) {
                                options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                            }
                            $("select#dsDivisionId").html(options1);
                            //$("select#gnDivisionId").html('<option value="0"> -- Select -- </option> ');
                            $("select#gnDivisionId").html('<option value="0">' + $('#select').val() + '</option> ');
                        });
            }
        }
    }

    function getGnDivisionByDsDivision() {
        var oSelect = document.getElementById('dsDivisionId');
        //var options1 = '<option value="0"> -- Select -- </option> ';
        var options1 = '<option value="0">' + $('#select').val() + '</option> ';
        for (var iCount = 0; oSelect.options[iCount]; iCount++) {
            if (oSelect.options[iCount].selected == true) {
                var id = oSelect.options[iCount].value;
                $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id: id, mode: 3},
                        function (data) {
                            var ds = data.gnDivisionList;
                            for (var i = 0; i < ds.length; i++) {
                                options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                            }
                            $("select#gnDivisionId").html(options1);
                        });
            }
        }
    }

</script>
<s:if test="editMode!=0">
    <div id="land-registration-module-home-title" class="module-home-title">
        <s:include value="../alienationApplicationNavigationInit.jsp"/>
    </div>
</s:if>
<div class="form-outer">
    <h2><s:label value="%{getText('initial_land_application.label')}"/> - <s:label
            value="%{getText('special_grant.label')}"/></h2>
    <hr/>
    <s:form action="addInitLandApplication.do" method="POST" id="gov-land-init-OutrightGrant-application-form"
            onsubmit="javascript:return (validateFormForInputDataSyntaxErrors('gov-land-init-OutrightGrant-application-form') && resetIncome() && selectList())"
            enctype="multipart/form-data">
        <fieldset class="submit-date-fieldset-style">
            <table class="submited-date-table">
                <tr>
                    <td><s:label value="%{getText('submit_date.label')}" cssClass="mandatory-field"/><s:label
                            value="%{getText('date_format.label')}" cssClass="date-format"/></td>
                    <td><s:textfield id="submitDate" name="landApplication.submitDate"
                                     onKeyPress="return dateNumbersOnly(event,true)"/></td>
                </tr>
            </table>
        </fieldset>

        <div id="tabs">
            <ul>
                <li><s:a href="#applicantDetails"><s:label
                        value="%{getText('details_of_applicant.label')}"/></s:a></li>
                <li><s:a href="#landAlienationDetails"><s:label value="%{getText('details_of_land.label')}"/></s:a></li>
                <li><s:a href="#otherDetails"><s:label value="%{getText('other_details.label')}"/></s:a></li>
            </ul>
            <div class="fieldset-style" id="applicantDetails">
                <table class="width-100">
                    <tr>
                        <td align="center" colspan="4">
                            <s:radio id="applicantType" name="holder.holderType"
                                     list="#@java.util.HashMap@{'1':getText('person.label'),'0':getText('institute.label')}"/>
                                <%--   <s:if test="editMode != 0">
                                 <s:hidden name="applicantType"/>
                             </s:if>   --%>
                        </td>
                    </tr>
                </table>
                <table class="width-100" id="division">
                    <s:if test="viewMode">
                        <tr>
                            <td><s:label value="%{getText('district.label')}"/></td>
                            <td><s:textfield id="districtId" name="districtName" cssClass="width-200-px"
                                             disabled="true"/></td>
                            <td><s:label value="%{getText('ds_division.label')}"/></td>
                            <td><s:textfield id="dsDivisionId" name="dsDivisionName" cssClass="width-200-px"
                                             disabled="true"/></td>
                        </tr>
                        <tr>
                            <td><s:label value="%{getText('gn_division.label')}"/><span class="mandatory-field"></span>
                            </td>
                            <td>
                                    <%-- <s:textfield id="gnDivisionId" name="holder.gnDivision.name" cssClass="width-200-px"/>--%>
                                <s:select id="gnDivisionId" name="holder.gnDivision.id" list="gnDivisionList"
                                          headerKey="0" headerValue="%{getText('select.label')}" cssClass="width-200-px"
                                          disabled="true"/>
                            </td>
                        </tr>
                    </s:if>
                    <s:else>
                        <tr>
                            <td><s:label value="%{getText('district.label')}"/></td>
                            <td><s:select id="districtId" name="districtId" list="districtListAll"
                                          onchange="getDsDivisionByDistrict()" headerKey="0"
                                          headerValue="%{getText('select.label')}"
                                          cssClass="width-200-px"/></td>
                            <td><s:label value="%{getText('ds_division.label')}"/></td>
                            <td><s:select id="dsDivisionId" name="dsDivisionId" list="dsDivisionList"
                                          onchange="getGnDivisionByDsDivision()" headerKey="0"
                                          headerValue="%{getText('select.label')}" cssClass="width-200-px"/></td>
                        </tr>
                        <tr>
                            <td><s:label value="%{getText('gn_division.label')}"/><span class="mandatory-field"></span>
                            </td>
                            <td>
                                <s:select id="gnDivisionId" name="holder.gnDivision.id" list="gnDivisionList"
                                          headerKey="0" headerValue="%{getText('select.label')}"
                                          cssClass="width-200-px"/>
                            </td>
                        </tr>
                    </s:else>
                </table>
                <table id="instituteDetails" class="width-100">
                    <tr>
                        <td colspan="4">
                            <s:include value="../instituteDetails.jsp"/>
                        </td>
                    </tr>
                </table>
                <table id="personDetails" class="width-100">
                    <tr>
                        <td colspan="4">
                            <s:include value="../personalDetails.jsp"/>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="fieldset-style" id="landAlienationDetails">
                <table class="width-100">
                    <tr>
                        <td><s:label value="%{getText('is_ltl_no_available.label')}"/></td>
                        <td><s:label value="%{getText('yes.label')}"/><input id="ltlYes" type="radio"
                                                                             name="ltl" value="0"
                                                                             onclick="hideLandDetails()"/></td>
                        <td colspan="2"><s:label value="%{getText('no.label')}"/><input type="radio"
                                                                                        id="ltlNo"
                                                                                        name="ltl"
                                                                                        checked="checked"
                                                                                        value="1"
                                                                                        onclick="showLandDetails()"/>
                        </td>
                    </tr>
                </table>
                    <%--<legend id="legend-land"><s:label value="%{getText('details_of_land.label')}"/></legend>
            <legend id="legend-agreement" style="display:none"><s:label
                    value="%{getText('agreement_details.label')}"/></legend>--%>

                <table class="width-100" id="agreement-no" style="display:none">
                    <td><s:label value="%{getText('agreement_no.label')}"/></td>
                    <td><s:textfield id="agreementNo" name="landApplication.agreementNo"/></td>
                    <td></td>
                </table>
                <table class="width-100" id="land-details">
                    <s:include value="../landAlienationDetails.jsp"/>
                </table>
                    <%-- <table class="width-100">
                     <tr>
                         <td>
                             <s:include value="../../documentUpload.jsp"/>
                         </td>
                     </tr>
                 </table>   --%>
            </div>
            <div class="fieldset-style" id="otherDetails">
                <table class="width-100">
                    <tr>
                        <td><s:label value="%{getText('purpose_of_the_requesting_land')}"/></td>
                        <td colspan="3"><s:textarea id="purposeId" cssClass="width-610-px"
                                                    name="landApplication.purpose"/></td>
                    </tr>
                </table>
            </div>
        </div>


        <hr/>
        <s:hidden name="alienationType" value="7"/>
        <s:hidden id="edit_mode" name="editMode"/>
        <s:include value="initFormSubmitButton.jsp"/>
    </s:form>
    <%--<s:include value="../approveRejectButton.jsp"/>--%>
</div>
<s:hidden id="pls_enter_applicant_name" value="%{getText('pls_enter_applicant_name')}"/>
<s:hidden id="pls_enter_submit_date" value="%{getText('pls_enter_submit_date')}"/>
<s:hidden id="pls_enter_applicant_address" value="%{getText('pls_enter_applicant_address')}"/>
<s:hidden id="pls_enter_valid_email" value="%{getText('pls_enter_valid_email')}"/>
<s:hidden id="pls_enter_valid_phone_No" value="%{getText('pls_enter_valid_phone_No')}"/>
<s:hidden id="pls_enter_valid_NIC_No" value="%{getText('pls_enter_valid_NIC_No')}"/>

<s:hidden id="pls_select_nationality" value="%{getText('pls_select_nationality.label')}"/>
<s:hidden id="pls_select_gnDivision" value="%{getText('pls_select_gnDivision.label')}"/>
<s:hidden id="pls_select_applicant_type" value="%{getText('pls_select_applicant_type.label')}"/>
<s:hidden id="select" value="%{getText('select.label')}"/>

<s:hidden id="pls_enter_annual_income" value="%{getText('pls_enter_annual_income')}"/>
<s:hidden id="pls_enter_valid_annual_income" value="%{getText('pls_enter_valid_annual_income')}"/>
<s:hidden id="pls_enter_the_applicant_dob" value="%{getText('pls_enter_the_applicant_dob.label')}"/>
<s:hidden id="applicant_age_validate" value="%{getText('applicant_age_validate.label')}"/>
